//
//  MainEntry.m
//  Ghac 4S
//
//  Created by apple on 11-8-22.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import "MainEntry.h"
#import <QuartzCore/QuartzCore.h>
#import "Global.h"
#import "LocationController.h"
#import "NewsControler.h"
#import "PartsPriceController.h"
#import "QAController.h"
#import "PartRepairController.h"
#import "ContactController.h"
#import "SSSSShopController.h"

@interface MainEntry(private)
-(void) initBtns;
@end

@implementation MainEntry
@synthesize btnList;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) 
    {
        // Custom initialization
//        NSString* filePath = [[NSBundle mainBundle] pathForResource:@"Property List" ofType:@"plist"];
//        NSMutableDictionary* list = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
//        NSLog(@"%@", filePath);
//        NSLog(@"%@", [list objectForKey:@"EntryBtn"]);
//        m_viewControllerList = [[NSMutableArray alloc] init];
//        m_navigateItemList = [[NSMutableDictionary alloc] init];
//       
//        navigationController = [MyNavigationController mainNavigationController];
//        [navigationController.view pushNavigationItem:[[UINavigationItem alloc] initWithTitle:@"main11" ] animated:YES];
        [self setTitle:@"main"];
        
    }
    return self;
}
//-(void)loadView
//{
//    
//}
-(void)viewDidLoad
{
    [super viewDidLoad];
    [self initBtns];

}
-(void)initBtns
{
    for (NSInteger i = 0; i < self.btnList.count; i++)
    {
        UIButton* button = [self.btnList objectAtIndex:i];
        NSString* imageurl = [NSString stringWithFormat:@"entry_btn_%d", i * 2];
        imageurl = [[NSBundle mainBundle] pathForResource:imageurl ofType:@"png"];
        UIImage* image = [UIImage imageWithContentsOfFile:imageurl];
        [button setImage:image forState:UIControlStateNormal];
        imageurl = [NSString stringWithFormat:@"entry_btn_%d", i * 2 + 1];
        imageurl = [[NSBundle mainBundle] pathForResource:imageurl ofType:@"png"];
        image = [UIImage imageWithContentsOfFile:imageurl];
        [button setImage:image forState:UIControlStateHighlighted];
    }
}
//-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
//{
//
//}
//-(void)makeTransition
//{
//    CATransition* animation = [CATransition animation];
//    [animation setDelegate:self];
//    [animation setDuration:0.2f];
//    [animation setType:kCATransitionPush];
//    [animation setSubtype:kCATransitionFromRight];
//    [[self.view layer] addAnimation:animation forKey:@"transition"];
//}
-(void)doEntryClick:(id)sender
{
    UIButton* pBtn = (UIButton*)sender;
    NSInteger indexOfBtn = [self.btnList indexOfObject:pBtn];
    id<MainViewSwitchAction> target = [Global mainRootController];
    UIViewController* controller;
    switch (indexOfBtn)
    {
        case 0:
            controller = [[PartRepairController alloc] init];
            [target showInnerView:controller];
            break;
        case 1:
            controller = [[PartsPriceController alloc] init];
            [target showInnerView:controller];
            break;
        case 2:
            
            break;
        case 3:
            controller = [[SSSSShopController alloc] init];
            [target showInnerView:controller];
            break;

    }
    [controller release];
    
    
    
//    NSString* label = pBtn.accessibilityLabel;
    

}

-(void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

-(void)dealloc
{
    [self viewDidUnload];
    [super dealloc];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
    [self.btnList removeAllObjects];
    self.btnList = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
